<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no"/>
		<meta name="HandheldFriendly" content="true"/>
		<meta name="MobileOptimized" content="320"/>
		<title>发表评价</title>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/jquery-1.9.1.min.js"></script>
		<script type="text/javascript" src="../../js/index.js"></script>
		<script type="text/javascript">
mui.plusReady(function() {
});

var base64_all = '' ;

//帖子发送方法
function onS(){
	
			var self = plus.webview.currentWebview();
			var type = self.type;
			var user_id = plus.storage.getItem('user_id');
			var message = $('#message').val();
			var base64Data=	plus.storage.getItem('base64Data1');
			if(message == ""){
				alert("评价内容不能为空");
				return ;
			}
//			var co_image = $('#headImgDiv img').  //图片
			mui.ajax({ //ajax请求
					url: getServerIp + 'AppCourse/commentCourse',
					type: 'POST',
					data: {    
						course_id:type,user_id:user_id,message:message,base64Data:base64Data
					}, //传参
					success: function(data, textStatus, jqXHR) {
						plus.storage.setItem('base64Data1','');
						alert(data.msg);
						mui.openWindow({
							url: 'commentMore.html',
							id: 'commentMore',
	                    	extras:{
	                        	type:type
	                        }
						});
					}
					});
			
			
}
 
        // 拍照
function getImage() {
	var cmr = plus.camera.getCamera();
	cmr.captureImage( function ( p ) {
		plus.io.resolveLocalFileSystemURL( p, function ( entry ) {
			
			//创建一个canvas
		    var c=document.createElement("canvas");
			//设置canvas宽高为图片宽高
			c.width=480;c.height=600;
			//将图片绘制到canvas
			var cxt=c.getContext("2d");
			var img=new Image();
			img.src=entry.toLocalURL();
			
		    img.onload = function (){
//              document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+entry.toLocalURL()+"'>";

                $("#headImgDiv").append("<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+entry.toLocalURL()+"'>");

	            $("#picture").hide();
	            $(".mui-backdrop").hide();
	        
			    cxt.drawImage(img,0,0,480,600);
			    
		         //得到图片的base64编码数据
			    var dd=c.toDataURL('image/png');
//				plus.storage.setItem('base64Data1',dd);
			    //log出图片base64数据
//			    console.log(dd);
			    //获取base64数据
			    var base64Data = dd.substr(21);
//			    console.log(base64Data);
                base64_all += '---'+base64Data;
                
				plus.storage.setItem('base64Data1',base64_all);
            }

	        
	
	//	createItem( entry );
		}, function ( e ) {
						plus.storage.setItem('base64Data1','');
//		alert( "读取拍照文件错误："+e.message );
		} );
	}, function ( e ) {
//	alert( "失败："+e.message );
	});
}



function galleryImg() {
	var user_id = plus.storage.getItem('user_id');
	// 从相册中选择图片
    plus.gallery.pick( function(path){
       //创建一个canvas
		    var c=document.createElement("canvas");
			//设置canvas宽高为图片宽高
			c.width=480;c.height=600;
			//将图片绘制到canvas
			var cxt=c.getContext("2d");
			var img=new Image();
			img.src=path;
			
		    img.onload = function (){
//              document.getElementById("headImgDiv").innerHTML="<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+path+"'>";
          
                $("#headImgDiv").append("<img id='loge_userImage' class='mui-media-object mui-pull-left' style='width: 20vw;height: 20vw;margin-left: 2vw;' src='"+path+"'>");

	            $("#picture").hide();
	            $(".mui-backdrop").hide();
	            
			    cxt.drawImage(img,0,0,480,600);
		        //得到图片的base64编码数据
			    var dd=c.toDataURL('image/png');
//				plus.storage.setItem('base64Data1',dd);
			    //log出图片base64数据
//			    console.log(dd);
			    //获取base64数据
			    var base64Data = dd.substr(21);
//			    console.log(base64Data);
                base64_all += '---'+base64Data;
                
				plus.storage.setItem('base64Data1',base64_all);
			}
//  	outLine(path);
        //showImg( path );
        //createItem(path);
    }, function ( e ) {
						plus.storage.setItem('base64Data1','');
    	outSet( "取消选择图片" );
    }, {filter:"image"} );
}
		</script>

		<link rel="stylesheet" href="../../css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-bar-nav~.mui-content {
				padding: 0;
			}
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
				padding: 10px 0;
                border-bottom: 1px solid #ddd;
			}
			.textarea_comment {
				margin-top: 45px;
			}
        </style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<button class="mui-action-back mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left">
				<span class="mui-icon mui-icon-left-nav" style="float: left;height: 40px;line-height: 40px;"></span>
				<img src="../../images/logo.png"  style=" height: 40px;"/>
			</button>
			<h1 class="mui-title">发表评价</h1>
			<a class="mui-icon mui-icon-right-nav" style="float: right;font-size: 18px;line-height: 30px;" onclick="onS();">发表</a>
		</header>
		<form style="padding: 11px 15px;">
		    <textarea rows="10" class="textarea_comment"  placeholder="说点什么吧" id="message"></textarea>
		    <div>
		    	<div id="headImgDiv"></div>
		    	<a href="#picture" style="display: none;"><img id="pic_r" style="width: 18vw;margin-left: 2vw;" src="../../images/addimg.png"/></a>
		    </div>
		</form>
		
				
		
		<div id="picture" class="mui-popover mui-popover-action mui-popover-bottom">
			<ul class="mui-table-view">
				<li class="mui-table-view-cell" style="height: 46px;"> 
				    <!--<input type="file" value="拍照上传"  onclick="getImage();"/>-->
					<a onclick="getImage();" style="position: absolute;width: 100%;left: 0;" >拍照上传</a>
				</li>
				<li class="mui-table-view-cell" style="height: 46px;">
					<a onclick="galleryImg()" style="position: absolute;width: 100%;left: 0;" >本地相册</a>
				</li>
			</ul>
			<ul class="mui-table-view">
				<li class="mui-table-view-cell" style="height: 46px;">
					<a href="#picture" style="position: absolute;width: 100%;left: 0;" ><b>取消</b></a>
				</li>
			</ul>
		</div>
	</body>
</html>